#include "qkeyboardbutton.h"


#include "../../libs/sharedlib/qkeyboardbuttonhost.h"
#include "../../libs/sharedLib/qabstractproperty.h"

#include <QStylePainter>
#include <QStyleOptionButton>
#include <QMouseEvent>

QKeyboardButton::QKeyboardButton(QWidget *parent) :
    QPushButton(parent),
    m_host(new SHAREDLIB::QKeyboardButtonHost(this))
{
    this->setProperty("objectName","keyboard_button");
    this->setProperty("className","KeyboardButton");
    this->setText("A");
    QFont f=font();
    f.setPointSize(20);
    setFont(f);
    this->resize(32,32);
    this->setFocusPolicy(Qt::NoFocus);
    connect(this,SIGNAL(clicked()),this,SLOT(clicked_slot()));
}

void QKeyboardButton::clicked_slot()
{
    QString code=property("clicked").toString();
    if(code!="")
    {
        QMap<QString,QString> param;
        param.insert("CapsLock",property("capslock").toString());
        m_host->emit_exec(code,param);
    }
}

void QKeyboardButton::setCapslock(const QString caps)
{
    if(m_capslock==caps)
    {
        return;
    }
    m_capslock=caps;

    QString code=property("capslock_changed").toString();
    if(code!="")
    {
        QMap<QString,QString> param;
        param.insert("CapsLock",caps);
        m_host->emit_exec(code,param);
    }
}

QString QKeyboardButton::capslock()
{
    return m_capslock;
}
